/*
* 生成手机卡类
* */

package Question3;

import java.util.regex.Pattern;

public class Card {

    private TypeEnum type; //卡类型
    private String phonenum; //卡号
    private String user; //用户名
    private String password; //密码
    private double balance; //账户余额
    private int callduraction; //通话时长(分钟)
    private int Intertraffic; //上网流量

    public Card() {}

    public Card(TypeEnum type, String phonenum, String user,
                String password, double balance, int callduraction,
                int Intertraffic) {
        setType(type);
        setPhonenum(phonenum);
        setUser(user);
        setPassword(password);
        setBalance(balance);
        setCallduraction(callduraction);
        setIntertraffic(Intertraffic);
    }
    

    public TypeEnum getType() {
        return type;
    }

    public void setType(TypeEnum type) {
        //手机卡的枚举值
        this.type = type;
    }

    public String getPhonenum() {
        return phonenum;
    }

    public void setPhonenum(String phonenum) {
        Pattern pattern = Pattern.compile("^[1]\\d{10}$");
        if(pattern.matcher(phonenum).matches()) this.phonenum = phonenum;
        else System.out.println("不是手机号！");
    }

    public String getUser() {
        return user;
    }

    public void setUser(String user) {
        this.user = user;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        Pattern pattern = Pattern.compile("^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z_]{8,12}$");
        if(pattern.matcher(password).matches()) this.password = password;
        else System.out.println("密码不符合规范！");
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }

    public int getCallduraction() {
        return callduraction;
    }

    public void setCallduraction(int callduraction) {
        this.callduraction = callduraction;
    }

    public int getIntertraffic() {
        return Intertraffic;
    }

    public void setIntertraffic(int Intertraffic) {
        this.Intertraffic = Intertraffic;
    }

    public void showCardInfo() {
        System.out.println("卡号：" + getPhonenum() + ";" + "用户名："
                + getUser() + ";" + "当前余额："+ getBalance() + ";");
    }
}
